<template>
    <div>
        <el-dialog class="AccountDialogBG" @close="closeWindow" v-model="dialogFlag" width="500" align-center>
            <p class="dialogTittle">忘记密码</p>
            <div class="dialogCont">
                <el-input v-model="Account.address.value" :prefix-icon="HomeFilled" placeholder="请输入您的区块链地址"></el-input>
                <el-input v-model="Account.password.value" :prefix-icon="Lock" placeholder="请输入新密码"
                    show-password></el-input>
                <el-input v-model="Account.ensurepassword.value" :prefix-icon="Lock" placeholder="请再次输入新密码"
                    show-password></el-input>
                <div class="elbutton">
                    <el-button @click="closeWindow" type="danger">取消</el-button>
                    <el-button @click="forgetPasswd" type="primary">确定</el-button>
                </div>
            </div>
        </el-dialog>
    </div>
</template>

<script setup lang='js' name=''>
import { ref, defineModel } from 'vue'
import { HomeFilled, Lock } from '@element-plus/icons-vue'
import showMessage from '@/utils/showMessage';
import { CheckInput } from '@/hooks/userCheckInput';
import getForgetAPI from '@/API/login/forget';
const dialogFlag = defineModel()

const Account = ref({
    address: { value: "", error: "请输您的区块链地址" },
    password: { value: "", error: "请输入密码" },
    ensurepassword: { value: "", error: "请再次输入密码" }
})

function closeWindow() {
    Account.value.address.value = ""
    Account.value.password.value = ""
    Account.value.ensurepassword.value = ""
    dialogFlag.value = false
}

function forgetPasswd() {
    if (CheckInput(Account.value.address.value, Account.value.address.error)) {
        if (CheckInput(Account.value.password.value, Account.value.password.error)) {
            if (Account.value.password.value == Account.value.ensurepassword.value) {
                ForgetAPI(Account.value.address.value, Account.value.password.value, Account.value.ensurepassword.value)
            } else {
                showMessage("两次密码不一致")
            }
        }
    }
}
async function ForgetAPI(address, password, confirm_password) {
    const res =await getForgetAPI(address, password, confirm_password)
    if(res.data.code==200){
        showMessage(res.data.msg,"success")
        closeWindow()
    }else{
        showMessage(res.data.msg)
    }
}
</script>
<style>
.AccountDialogBG {
    background: var(--ACDialogBG);
}
</style>
<style scoped>
/* 标题 */
.dialogTittle {
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 20px;
    color: var(--ACDialogTittle);
}

/* 内容框架 */
.dialogCont {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.elbutton {
    display: flex;
}

.elbutton>* {
    flex: 1;
}
</style>
